package com.semp.jadoma.web.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;

import com.semp.jadoma.core.model.Dog;
import com.semp.jadoma.web.bean.DogBean;
import com.semp.jadoma.web.form.DogDisplayForm;
import com.semp.jadoma.web.utils.webapp.Forward;
import com.semp.jadoma.web.utils.webapp.Session;

public class DogDisplayAction extends RootAction {

	@Override
	public String executeChild(ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
		/*
		 * Find the dog
		 */
		DogDisplayForm dogDisplayForm = (DogDisplayForm) form;
		Dog dog = dogService.findDog(dogDisplayForm.getDogId());
		
		if (dog == null) {
			/*
			 * No dog found
			 */
			return Forward.FAILURE;
		} else {
			/*
			 * Store dog bean in request
			 */
			request.setAttribute(Session.BEAN_DOG, new DogBean(dog));
			return Forward.SUCCESS;
		}
	}

}
